package top.chmin.project.cloud.sys.index.info;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import top.chmin.project.cloud.common.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;



/**
 * chmin
 * 2024-01-26 13:55:57
 * cloud-code
 */
public class IndexInfoCondition extends Condition {
    private IndexInfoCondition parent = null;

    IndexInfoCondition() {
    }

    private IndexInfoCondition(IndexInfoCondition condition) {
        this.parent = condition;
    }

    public static IndexInfoCondition forDelete() {
        IndexInfoCondition condition = new IndexInfoCondition();
        condition.setSql("DELETE FROM sys_index_info#where##group##order##limit#");
        return condition;
    }

    public static IndexInfoCondition forSelect() {
        IndexInfoCondition condition = new IndexInfoCondition();
        condition.modelClass = IndexInfo.class;
        condition.setSql("SELECT #select# FROM sys_index_info#where##group##order##limit#");
        return condition;
    }

    public IndexInfoCondition distinct() {
        this.distinct = true;
        return this;
    }

    public IndexInfoCondition limit(int limit) {
        this.limit = " LIMIT " + limit;
        return this;
    }

    public IndexInfoCondition sub() {
        return new IndexInfoCondition(this);
    }

    public IndexInfoCondition finish() {
        if (!whereList.isEmpty()) {
            parent.whereList.add("(" + String.join(" OR ", whereList) + ")");
        }
        parent.whereValueList.addAll(whereValueList);
        return parent;
    }

    public IndexInfo selectFirst() {
        return selectFirst(IndexInfo.class);
    }

    public List<IndexInfo> selectList() {
        return selectList(IndexInfo.class);
    }

    public Stream<IndexInfo> selectStream() {
        return selectStream(IndexInfo.class);
    }

    public Page<IndexInfo> selectPage() {
        return selectPage(IndexInfo.class);
    }

    /*###########auto#start###########*/
    public static int deleteByIndexCode(String indexCode) {
        return forDelete().indexCode().eq(indexCode).execute();
    }

    public static IndexInfo selectByIndexCode(String indexCode) {
        return forSelect().indexCode().eq(indexCode).selectFirst(IndexInfo.class);
    }

    public static <T> T selectByIndexCode(String indexCode, Class<T> clazz) {
        return forSelect().indexCode().eq(indexCode).selectFirst(clazz);
    }

    public static int deleteByIndexName(String indexName) {
        return forDelete().indexName().eq(indexName).execute();
    }

    public static IndexInfo selectByIndexName(String indexName) {
        return forSelect().indexName().eq(indexName).selectFirst(IndexInfo.class);
    }

    public static <T> T selectByIndexName(String indexName, Class<T> clazz) {
        return forSelect().indexName().eq(indexName).selectFirst(clazz);
    }

    /*###########auto##end############*/
    /* append $conditionIndexAppender$ */
    /*###########auto#start###########*/
    public CreateBy createBy() {
        return new CreateBy();
    }

    public class CreateBy extends StringFlexColumn<IndexInfoCondition> {
        private CreateBy() {
            super(IndexInfoCondition.this, "create_by");
        }
    }

    public CreateTime createTime() {
        return new CreateTime();
    }

    public class CreateTime extends LocalDateTimeFlexColumn<IndexInfoCondition> {
        private CreateTime() {
            super(IndexInfoCondition.this, "create_time");
        }
    }

    public Id id() {
        return new Id();
    }

    public class Id extends IntegerFlexColumn<IndexInfoCondition> {
        private Id() {
            super(IndexInfoCondition.this, "id");
        }
    }

    public IndexCode indexCode() {
        return new IndexCode();
    }

    public class IndexCode extends StringFlexColumn<IndexInfoCondition> {
        private IndexCode() {
            super(IndexInfoCondition.this, "index_code");
        }
    }

    public IndexName indexName() {
        return new IndexName();
    }

    public class IndexName extends StringFlexColumn<IndexInfoCondition> {
        private IndexName() {
            super(IndexInfoCondition.this, "index_name");
        }
    }

    public IndexUnique indexUnique() {
        return new IndexUnique();
    }

    public class IndexUnique extends StringFlexColumn<IndexInfoCondition> {
        private IndexUnique() {
            super(IndexInfoCondition.this, "index_unique");
        }
    }

    public TableCode tableCode() {
        return new TableCode();
    }

    public class TableCode extends StringFlexColumn<IndexInfoCondition> {
        private TableCode() {
            super(IndexInfoCondition.this, "table_code");
        }
    }

    public UpdateBy updateBy() {
        return new UpdateBy();
    }

    public class UpdateBy extends StringFlexColumn<IndexInfoCondition> {
        private UpdateBy() {
            super(IndexInfoCondition.this, "update_by");
        }
    }

    public UpdateTime updateTime() {
        return new UpdateTime();
    }

    public class UpdateTime extends LocalDateTimeFlexColumn<IndexInfoCondition> {
        private UpdateTime() {
            super(IndexInfoCondition.this, "update_time");
        }
    }

    /*###########auto##end############*/
    /* append $conditionFieldAppender$ */
}
